<?php
    $this->layout('base.phtml', [
        'title' => _('Group edition'),
        'canonical' => url_full('edit group', ['id' => $group->id]),
        'has_errors' => $error || $errors,
        'modal_enabled' => true,
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1 id="modal-title"><?= _('Group edition') ?></h1>
    </div>

    <form method="post" action="<?= url('update group', ['id' => $group->id]) ?>">
        <?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

        <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />
        <input type="hidden" name="from" value="<?= $from ?>" />

        <div class="form-group <?= isset($errors['name']) ? 'form-group--invalid' : '' ?>">
            <label for="name">
                <?= _('The name of your group') ?>
                <span class="label__help">
                    <?= _f('(max. %d characters)', $name_max_length) ?>
                </span>
            </label>

            <input
                id="name"
                name="name"
                type="text"
                required
                value="<?= $name ?>"
                autocomplete="off"
                autofocus
                maxlength="<?= $name_max_length ?>"
                aria-describedby="name-desc"
            />

            <div id="name-desc">
                <?php if (isset($errors['name'])): ?>
                    <p class="form-group__error">
                        <span class="sr-only"><?= _('Error') ?></span>
                        <?= $errors['name'] ?>
                    </p>
                <?php endif; ?>
            </div>
        </div>

        <div class="form__actions">
            <button type="submit" class="button--primary">
                <?= _('Save changes') ?>
            </button>
        </div>
    </form>

    <form
        class="form--danger"
        method="post"
        action="<?= url('delete group', ['id' => $group->id]) ?>"
        data-turbo-confirm="<?= _('Are you sure that you want to delete this group? The associated collections will NOT be deleted.') ?>"
    >
        <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />
        <input type="hidden" name="from" value="<?= $from ?>" />

        <button type="submit" class="button--danger">
            <?= icon('trash') ?>
            <?= _('Delete the group') ?>
        </button>
    </form>
</div>
